import bizCsFields as bcf


def transFbTask(fb_task, parent_tasks):
    task_status_map = bcf.getFbTaskStatusMap()
    task = {}
    task["task_id"] = fb_task["id"]
    task["task_no"] = "DB-" + str(fb_task["uniqueId"])
    task["task_status"] = task_status_map.get(str(fb_task["tfsId"]), "未知状态")
    task["estimate_workload"] = 0
    task["biz_team"] = "未定义"
    task["task_type"] = "未定义"
    task["frontend"] = "未定义"
    task["backend"] = "未定义"
    task["test"] = "未定义"
    task["main_customer"] = "未定义"
    task["is_father"] = fb_task["id"] in parent_tasks
    for cf in fb_task["customfields"]:
        if len(cf["value"]) == 0:
            continue
        # 主责客户
        if cf["cfId"] == "61123175d7d6065f66ee29e7":
            task["main_customer"] = cf["value"][0]["title"]
        # 需求分类
        elif cf["cfId"] == "5ce4d1abb644a600011cf268":
            task["task_type_original"] = cf["value"][0]["title"]
            if "客成" in task["task_type_original"]:
                task["task_type"] = "客成需求"
            elif "交付" in task["task_type_original"]:
                task["task_type"] = "交付需求"
            elif "产品规划" in task["task_type_original"]:
                task["task_type"] = "产品规划"
            elif "技术规划" in task["task_type_original"]:
                task["task_type"] = "技术规划"
            else:
                task["task_type"] = "内部需求"
        elif cf["cfId"] == "61810ffc967570acea7feabd":
            task["estimate_workload"] = float(cf["value"][0]["title"]) or 0
        elif cf["cfId"] == "5f93e91719e65b9393474e07":
            task["biz_team"] = cf["value"][0]["title"]
        elif cf["cfId"] == "660be84c797f388d73107b34":
            task["frontend"] = cf["value"][0]["title"]
        elif cf["cfId"] == "660be86cfdae364d32426542":
            task["backend"] = cf["value"][0]["title"]
        elif cf["cfId"] == "660be8a675863a6977f65356":
            task["test"] = cf["value"][0]["title"]

    return task
